
             
/**
 * Copyright (c) 2012-2013 JLLT Corp. 2012-2013,All Rights Reserved.
 * This software is published under the 金麟龙腾商贸有限公司.
 * License version 1.0, a copy of which has been included with this
 * distribution in the LICENSE.txt file.
 *
 * @File name:  AddTProductCommentAction.java   添加【会员商品评论信息:T_PRODUCT_COMMENT】
 * @Create on:  2012-10-27 19:50:206
 * @Author   :  陈伟
 *
 * @ChangeList
 * ---------------------------------------------------
 * Date         Editor              ChangeReasons
 *
 */
           
        
package com.boho.ecp.member.action;

            
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import cn.boho.framework.actions.ActionImp;
import cn.boho.framework.context.ActionContext;
import cn.boho.framework.exception.UserOperationException;
import cn.boho.framework.po.DynaBeanMap;
import cn.boho.framework.po.POUtils;
import cn.boho.framework.po.SArrayList;
import cn.boho.framework.service.MessageService;
import cn.boho.framework.utils.HTMLFilter;

import com.boho.ecp.constant.Comment;
import com.boho.ecp.constant.Member;
import com.boho.ecp.constant.Order;
import com.boho.ecp.order.service.OrderService;
import com.boho.ecp.po.TProductCommentPO;
import com.boho.ecp.product.service.ProductService;
import com.boho.ecp.util.ArrayUtils;

public class AddTProductCommentListAction extends ActionImp {
	private Connection con=null;
	@Override
	protected void doException(ActionContext atx, Exception ex) {
		if (!(ex instanceof UserOperationException)) {
			atx.setErrorContext("BOHO_COMMON_1001", MessageService.getMessage("BOHO_COMMON_1001"),"【会员商品评论信息】", ex);
		}
	}
	@Override
	protected int performExecute(ActionContext atx) throws Exception {
		con = atx.getConection();
		Date date = new Date();
		DynaBeanMap dbm = (DynaBeanMap)atx.getSessionValue(Member.MEMBER_SESSEION);
		String orderId = atx.getStringValue("ORDER_ID");
		Integer memberId = (Integer)dbm.get("MEMBER_ID");
		String memberName = (String)dbm.get("MEMBER_ACCOUNT");
		Integer[] productIds = ArrayUtils.ObjArrayToIntArray(atx.getArrayValue("PRODUCT_ID"));
		String[] comments = ArrayUtils.ObjArrayToStringArray(atx.getArrayValue("COMMENT_TEXT"));
		String[] scores = ArrayUtils.ObjArrayToStringArray(atx.getArrayValue("SCORE"));
		SArrayList poList = new SArrayList();
		List idList = new ArrayList();
		for (int i = 0; i < comments.length; i++) {
			String comment = HTMLFilter.filter(comments[i].trim());
			if(StringUtils.isBlank(comment)){
				comment = "好评！";
			}
			TProductCommentPO tProductCommentPO = new TProductCommentPO();
			tProductCommentPO.setMemberId(memberId);
			tProductCommentPO.setMemberAccount(memberName);
			tProductCommentPO.setProductId(productIds[i]);
			tProductCommentPO.setScore(scores[i]);
			tProductCommentPO.setCommentText(comment);
			tProductCommentPO.setIsPass(Comment.WAIT);
			tProductCommentPO.setCommentDate(date);
			tProductCommentPO.setCreateBy(memberId.toString());
			tProductCommentPO.setCreateDate(date);
			poList.add(tProductCommentPO);
			idList.add(productIds[i]);
		}
		POUtils.insertPoList(con, poList, false);
		ProductService.batchUpdateReturnByProductIds(con, idList);
		OrderService.updateOrderCommentStatus(con, orderId, Order.FEEDBACKED, memberId.toString());
		return 1;
	}
	@Override
	protected int verifyParameters(ActionContext atx) throws Exception {
		return 1;
	}
}
